package oauth.repository.mapperadd;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Select;

import oauth.repository.model.SysFinger;
import oauth.repository.modelAdd.SysFingerDTO;
import oauth.repository.modelAdd.SysUserRoleRescsDTO;

public interface SpringSecurityMapper
{
	@Select("SELECT sr.resc_string rescString,sre.role_name roleName " +
			"FROM sys_resources sr JOIN sys_role_rescs rr " +
			"ON sr.id = rr.rescs_id JOIN sys_role sre ON sre.id = rr.role_id")
	List<SysUserRoleRescsDTO> selectAllURL_Role();

	@Select("SELECT u.username, u.password, r.role_name roleName " +
			"FROM sys_users u JOIN  sys_users_role ur ON u.id = ur.users_id JOIN sys_role r " +
			"ON r.id = ur.role_id WHERE u.username = #{username}")
	List<SysUserRoleRescsDTO> selectUPRByUsername(String username);

	@Select("SELECT u.username user_name, f.finger_id, f.finger_code " +
			"FROM sys_users u JOIN sys_finger f ON u.id = f.user_id")
	List<SysFingerDTO> selectAllFingerCode();

	@Select("SELECT u.username user_name, f.finger_id, f.finger_code " +
			"FROM sys_users u JOIN sys_finger f ON u.id = f.id " +
			"WHERE u.username = #{username}")
	List<SysFingerDTO> selectFingerCodeByUsername(String username);

	@Select("SELECT f.* FROM sys_users u JOIN sys_finger f ON u.id = f.user_id " +
			"WHERE u.username=#{username}")
	List<SysFinger> selectSysFingerByUsername(String username);

	@Select("SELECT f.id, f.user_id userId, f.finger_id fingerId, f.finger_code fingerCode," +
			"  f.operator_time operatorTime , f.finger_pic fingerPic FROM sys_finger f " +
			"WHERE f.user_id  = #{userId}")
	List<SysFinger> selectSysFingerByUserId(BigDecimal userId);

	// @Update("UPDATE sys_finger SET user_id = #{userId}, finger_id = #{fingerId}, " +
	// "finger_code = #{fingerCode}, finger_pic = #{fingerPic} WHERE " +
	// "user_id = #{userId} AND finger_id = #{fingerId}")
	int updateSysFingerByUserIdAndFingerId(SysFinger record);
}
